package net.betou.web;

import static net.betou.web.Constants.RES_PATH;
import static net.betou.web.Constants.TPLDIR_COMMON;
import static net.betou.web.Constants.TPL_BASE;
import static net.betou.web.Constants.TPL_SUFFIX;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;


/**
 * 前台工具类
 * 
 * @author 叶装装
 * 
 */
public class FrontUtils{

	/**
	 * 模板资源路径
	 */
	public static final String RES_TPL = "res";

	/**
	 * 部署路径
	 */
	public static final String BASE = "base";

	/**
	 * 获得模板路径
	 * 
	 * @param dir
	 *            模板目录
	 * @param name
	 *            模板名称, 不经本地化处理
	 * @return
	 */
	public static String getTplPath( String dir, String name ) {
		return TPL_BASE + "/" + dir + "/" + name + TPL_SUFFIX;
	}

	public static void frontData( HttpServletRequest request, Map< String, Object > map ) {
		String ctx = request.getContextPath( );
		map.put( BASE, ctx );

		String res = ctx + RES_PATH;
		// res路径需要去除第一个字符'/'
		map.put( RES_TPL, res );
	}

	public static String showMessage( HttpServletRequest request, Map< String, Object > model, List< String > errors ) {
		frontData( request, model );
		model.put( "errors", errors );
		return "/WEB-INF/" + TPLDIR_COMMON + "/trade_error_message.html"; //getTplPath( TPLDIR_COMMON, "trade_error_message" );
	}
}
